package com.xyq.fs.index;

import java.nio.file.Path;
import java.nio.file.Paths;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.TextField;

import com.xyq.fs.base.MyDirectoryS;
import com.xyq.fs.constants.FieldConstant;
import com.xyq.fs.contants.filesuffixes2.WordEnums;

public class IndexWordFiles implements IndexFileInf {

	@Override
	public void indexFile(Path path, String bz) {

		String ps = path.toString().toUpperCase();
		Document doc = null;
		String content = "";
		if (ps.endsWith(WordEnums.DOC)) {
			doc = getSimDoc(path, WordEnums.DOC, bz);
		} else if (ps.endsWith(WordEnums.DOCX)) {
			doc = getSimDoc(path, WordEnums.DOCX, bz);
		} else if (ps.endsWith(WordEnums.WPS)) {
			doc = getSimDoc(path, WordEnums.WPS, bz);
		}
		if (doc != null) {
			content = getContent(path);
			TextField tf = new TextField(FieldConstant.FILE_CONTENT, content, Store.NO);
			doc.add(tf);
			tf = null;
		}
		MyDirectoryS.addDocument(doc);
		doc.clear();
		doc = null;
		ps = null;
		content = null;
		path = null;
		bz = null;
	}

	public static void main(String[] args) {

		IndexWordFiles iw = new IndexWordFiles();
		String str = iw.getContent(Paths.get("d:\\1.wps"));
		System.out.println(str.trim());
	}

}
